package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.Menu;
import com.indusfo.spc.pojo.User;
import com.indusfo.spc.service.MenuService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜单信息接口
 * 
 * @author 贺闻博
 * 
 *         2018年11月30日
 */
@Controller
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * 根据用户的上级菜单查询他的下级菜单
     * 
     * @Title: MenuController
     * @return
     */
    @RequestMapping(value = "selectMenuAll")
    @ResponseBody
    public JSONObject slectMenuAll(String vcMenuPar) {
        JSONObject menu = menuService.selectMenuS(vcMenuPar);
        return menu;
    }

    /**
     * 登陆后,根据用户Id查询角色菜单
     * 
     * @Title: MenuController
     * @param req , resp
     * @return
     */
    @RequestMapping(value = "selectMenuByUserId", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
    @ResponseBody
    public List<Menu> selectMenuByUserId(HttpServletRequest req, HttpServletResponse resp) {
        User user = (User)req.getSession().getAttribute("user");
        List<Menu> menus = null;
        if (user != null) {
            menus = menuService.selMenus(user);
        }

        return menus;
    };

}
